﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

using CSF.Security.Data;
using CSF.Security.BLL;
using CSF.Security.Service;
using CSF.BusinessCore.Service;

namespace CSF.Service.Accounts
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“UserAccountSvc”。
    [ErrorHandleBehavior]
    public class UserAccountSvc : IUserAccountSvc
    {

        #region IDataIdKeyService<UserAccount> 成员

        public UserAccount GetOneById(int id)
        {
            UserAccountBLL bll = new UserAccountBLL();
            return bll.GetOneById(id);
        }

        public bool UpdateById(UserAccount t, int id)
        {
            UserAccountBLL bll = new UserAccountBLL();
            int count = bll.Update(t, p => p.Id == id);
            return count > 0;
        }

        public bool DeleteOneById(int id)
        {
            UserAccountBLL bll = new UserAccountBLL();
            return bll.DeleteOneById(id);
        }

        #endregion

        #region IDataEntityService<UserAccount> 成员

        public List<UserAccount> GetAll()
        {
            UserAccountBLL bll = new UserAccountBLL();
            return bll.GetAll();
        }

        public int Insert(UserAccount entity)
        {
            UserAccountBLL bll = new UserAccountBLL();
             bll.Insert(entity);
             return entity.Id;
        }

        #endregion

        #region IUserAccountSvc 成员

        public IEnumerable<int> GetUserRoles(int userId)
        {
            UserAccountBLL bll = new UserAccountBLL();
            return bll.GetUserRoles(userId);
        }

        public void SetUserRole(int userId, IEnumerable<int> roleIds, string createBy)
        {
            UserAccountBLL bll = new UserAccountBLL();
            bll.SetUserRole(userId, roleIds, createBy);
        }

       


        #endregion

        #region IDataIdKeyService<UserAccount> 成员


        public int DeleteById(IEnumerable<int> ids)
        {
            UserAccountBLL bll = new UserAccountBLL();
            return bll.DeleteById(ids);
        }

        #endregion

        #region IUserAccountSvc 成员


        /// <summary>
        /// 更新自己的账户信息
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public bool UpdateBySelf(UserAccount account)
        {
            UserAccountBLL bll = new UserAccountBLL();
            return bll.UpdateBySelf(account);
        }

        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <param name="oldPassword">旧密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns></returns>
        public bool ChangePassword(int userId, string oldPassword, string newPassword, string changeBy)
        {
            UserAccountBLL bll = new UserAccountBLL();
            return bll.ChangePassword(userId, oldPassword, newPassword, changeBy);
        }

        #endregion


       
    }
}
